package com.netsdk.common;

import com.netsdk.entity.JsonData;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.utils.DeviceModule;
import com.netsdk.utils.DingYue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class DaHuaDevice {
    private static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;


    //登录
    public static boolean login(String ip,int port,String name,String password){
        return DeviceModule.login(ip,port,name,password);
    }

    //登出
    public static void loginOut(){

    }

    //添加人员
    public static JsonData updatePerson(Map<String,Object> paramMap,int type){
        return DeviceModule.updatePerson(paramMap,type);
    }

    //添加人脸
    public static JsonData addFace(Map<String,Object> paramMap){
        //先删除原有人脸
        boolean isSuccess = DeviceModule.deleteFace(paramMap);
        if(isSuccess){
            return DeviceModule.addFace(paramMap);
        }else{
            return JsonData.buildError("删除原有人脸出错");
        }
    }

    //远程开门
    public static JsonData open(String serialNumber){
        return DeviceModule.openDoor(serialNumber);
    };

    //删除人员
    public static JsonData deletePerson(Map<String,Object> paramMap){
        return DeviceModule.deletePerson(paramMap);
    }

//    //sdk初始化
//    @PostConstruct
//    void init(){
//        DeviceModule.init(null,null);
//    }

    public static void startDingYue(){
        //所有设备开启订阅
        DingYue.startDingYue();
    }

}
